package com.hotel.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hotel.model.auto.Role;
import com.hotel.model.auto.Roomtype;
import com.hotel.service.IRoomtypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author
 * @since 2023-04-03
 */
@RestController
@RequestMapping("/roomtype")
public class RoomtypeController {
    @Autowired
    private IRoomtypeService iRoomtypeService;

    /*查询房间类型*/
    @GetMapping("/getRoomtype")
    public List<Roomtype> getRoomtype() {
        return iRoomtypeService.list();
    }

    /*通过id查询房间类型*/
    @GetMapping("/getRoomTypeById/{id}")
    public Roomtype getRoomtypeById(@PathVariable("id") int id) {
        return iRoomtypeService.getById(id);
    }

    /*修改房间类型*/
    @PostMapping("/updateRoomtype")
    public void updateRoomtype(@RequestBody Roomtype roomtype) {
        iRoomtypeService.updateById(roomtype);
    }

    /*添加房间类型*/
    @PostMapping("/setRoomtype")
    public void setRoomtype(@RequestBody Roomtype roomtype) {
        iRoomtypeService.save(roomtype);
    }

    /*删除房间类型*/
    @PostMapping("/deletedById/{id}")
    public boolean deleted(@PathVariable("id") int id) {
        return iRoomtypeService.removeById(id);
    }

    /*批量删除房间类型*/
    @PostMapping("/deletedAllById")
    public boolean deletedAllById(@RequestBody int[] delarr) {
        for (int i : delarr) {
            System.out.println(i);
            iRoomtypeService.removeById(i);
        }
        return true;
    }

    /*模糊查询房间类型数据*/
    @PostMapping("/selectRoomType/{input}")
    public List<Map<String, Object>> selectInfo(@PathVariable("input") String value) {
        System.out.println(value);
        QueryWrapper<Roomtype> queryWrapper = new QueryWrapper<>();
        /*核心模糊算法*/
        queryWrapper.like("name", value).or().like("description", value).or().like("price", value);
        List<Map<String, Object>> maps = iRoomtypeService.listMaps(queryWrapper);
        return maps;
    }

    /*更新房间类型总数*/
    @GetMapping("/updateRoomTypeNum")
    public int updateRoomTypeNum() {
        return iRoomtypeService.updateRoomTypeNum();
    }

    /*更新可预定房间数*/
    @GetMapping("/updateRoomTypeStore")
    public int updateRoomTypeStore() {
        return iRoomtypeService.updateRoomTypeStore();
    }
}
